package wxk.interview.serializable;

import java.io.*;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/9.
 * @since 2.2
 */
public class PersonSingletonTest {

    public static void main(String[] args) {

        PersonSingle single1 = PersonSingle.getInstance();
        PersonSingle single2 = PersonSingle.getInstance();
        System.out.println(single1);
        System.out.println(single1 == single2);

        File file = new File("personSingleton.out");
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(single1);

            ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
            PersonSingle single3 = (PersonSingle) inputStream.readObject();
            System.out.println(single3);
            System.out.println(single1 == single3);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
